
package com.onstar.cn.api;

import android.util.Log;

import com.onstar.cn.api.framework.ClazzInjectUtils;
import com.onstar.cn.api.framework.annotation.Path;
import com.onstar.cn.api.framework.annotation.PathParams;
import com.onstar.cn.api.framework.annotation.RequestMapping;
import com.onstar.cn.framework.network.entity.RequestEntity;
import com.onstar.cn.framework.utils.GsonHelper;
import com.onstar.cn.mag.dealer.MaintenanceDealerEntity;
import com.onstar.cn.mag.dealer.PreferredDealerEntity;
import com.onstar.cn.mag.dealer.ReqAroundDealersEntity;

/**   
 * @Title: DealersService.java 
 * @author Xiaofeng Feng
 * @date 2015年8月11日 下午2:15:18 
 */
@Path("/msp/api/v3/user")
public class DealersService {
	
	private String serverURL;
	/**
	 * 
	* @Description: TODO
	* @author Xiaofeng Feng
	* @date 2015年8月11日 下午2:15:18 
	 */
	public DealersService(String serverURL) {
		this.serverURL = serverURL;
	}
	
	/**
	 * @Title: AroundDealersService @Description:
	 * /msp/api/v3/user/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/dealers/around
	 * request method:PUT @param 设定文件 @return void
	 * 返回类型 @throws
	 */
	// http://localhost:8080/msp/api/v3/user/subscriber/111/accounts/222/vehicles/333/dealers/around?pageNumber=0&ps=3
	//	{"radius":"5","returnPreferredDealer":"true","cityCode":"SH","dealerBrand":"BUICK","currentLocation":{"longitude":34.555,"latitude":12.333},"queryType":"AROUND"}
	//@RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/dealers/around")
	@RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/dealers/around")
	public RequestEntity getAroundDealersService(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
			@PathParams("accountID") String accountID, @PathParams("vin") String vin,
			ReqAroundDealersEntity ReqAroundDealers,@PathParams("pageNumber") Integer pageNumber, @PathParams("pageSize") Integer pageSize) {
		if (entity == null) {
			entity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "getAroundDealersService", entity,subscriberID, accountID,vin,ReqAroundDealers,pageNumber, pageSize);
		entity.setBody(GsonHelper.toJson(ReqAroundDealers));
		entity.setUrl(serverURL+url+"?pageNumber=" + (pageNumber <= 0 ? 0 : pageNumber) + "&pageSize="
				+ (pageSize <= 0 ? 10 : pageSize));
		return entity;
	}
	
	
	/**
	 * @Title: DealersService @Description:
	 * /msp/api/v3/user/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/dealer/prefer
	 * request method:PUT @param 设定文件 @return void
	 * 返回类型 @throws
	 */
	@RequestMapping("/subscriber/{subscriberID}/accounts/{accountID}/vehicles/{vin}/dealers/prefer")
	public RequestEntity getPreferredDealer(RequestEntity entity, @PathParams("subscriberID") String subscriberID,
			@PathParams("accountID") String accountID, @PathParams("vin") String vin,PreferredDealerEntity dealerEntity) {
		if (entity == null) {
			entity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "getPreferredDealer", entity,subscriberID, accountID,vin,dealerEntity);
		entity.setUrl(serverURL+url);
		return entity;
	}

	/**
	 * @Title: DealersService @Description:
	 * /msp/api/v3/user/subscriber/{idpID}/accounts/{accountID}/vehicles/{vin}/ maintenance/dealers
	 * request method:PUT @param 设定文件 @return void
	 * 返回类型 @throws
	 */
	@RequestMapping("/subscriber/{idpID}/accounts/{accountID}/vehicles/{vin}/maintenance/dealers")
	public RequestEntity getMaintenanceDealers(RequestEntity entity, @PathParams("idpID") String idpID,
											   @PathParams("accountID") String accountID, @PathParams("vin") String vin,MaintenanceDealerEntity dealerEntity) {
		if (entity == null) {
			entity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "getMaintenanceDealers", entity,idpID, accountID,vin,dealerEntity);
		entity.setBody(GsonHelper.toJson(dealerEntity));
		entity.setUrl(serverURL+url);
		return entity;
	}

	/**
	 * @Title: DealersService @Description:
	 * /msp/api/v3/user/subscriber/{idpID}/accounts/{accountID}/vehicles/{vin}/ maintenance/order
	 * request method:PUT @param 设定文件 @return void
	 * 返回类型 @throws
	 */
	@RequestMapping("/subscriber/{idpID}/accounts/{accountID}/vehicles/{vin}/maintenance/order")
	public RequestEntity getMaintenanceOrder(RequestEntity entity, @PathParams("idpID") String idpId,
											 @PathParams("accountID") String accountID, @PathParams("vin") String vin,MaintenanceDealerEntity dealerEntity) {
		if (entity == null) {
			entity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "getMaintenanceOrder", entity,idpId, accountID,vin,dealerEntity);
		if(dealerEntity!=null) {
			String json=GsonHelper.toJson(dealerEntity);
			Log.d("test", "json:" + json);
			entity.setBody(GsonHelper.toJson(dealerEntity));
		}
		entity.setUrl(serverURL+url+"?vin="+vin);
		return entity;
	}
	
	/**
	* @Title: getHomeAndCompanyAddressInfo
	* @Description: 获取家和公司的地址信息
	* @param @param entity
	* @param @param IDPID
	* @param @return
	* @return RequestEntity
	 */
	@RequestMapping("/{IDPID}/destinations")
	public RequestEntity getHomeAndCompanyAddressInfo(RequestEntity entity,@PathParams("IDPID") String IDPID){
		if (entity == null) {
			entity = new RequestEntity();
		}
		String url = ClazzInjectUtils.injectUrl(getClass(), "getHomeAndCompanyAddressInfo", entity,IDPID);
		entity.setUrl(serverURL + url);
		return entity;
	}
}

